cmake_minimum_required(VERSION 3.8)
project(motion_controller)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

#GDB ros在线调试
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
# ros2 run --prefix 'gdb -ex run --args' [package_name] [node_name] 

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(Eigen3)
find_package(base_interface REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)


# 添加非ROS2功能包的依赖项时，需要将其对应的头文件路径在include_directories中写明。
# 而对于依赖项为ROS2功能包时，则无需此操作。
include_directories(
  include
  ${EIGEN3_INCLUDE_DIRS}
  /usr/include/eigen3/Eigen
  /usr/local/include  #添加这一行，对代码编译后会在该路径下生成所需的头文件
)

#规定.so/.a库文件路径
link_directories(
  /usr/local/lib #添加这一行，对代码编译后会在该路径下生成所需的库
)

FILE(GLOB SOURCE_LIST "src/*.cpp"
)


add_executable(motion_controller ${SOURCE_LIST})

target_include_directories(motion_controller PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
target_compile_features(motion_controller PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

ament_target_dependencies(
  motion_controller
  "rclcpp"
  ###
  "base_interface"
  "std_msgs"
  
  "nav_msgs"
  "geometry_msgs"
  "visualization_msgs"
)

install(TARGETS motion_controller
  DESTINATION lib/${PROJECT_NAME})

# 自己加入，将launch文件夹中的launch文件安装到install中
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
# install(DIRECTORY maps DESTINATION share/${PROJECT_NAME})
install(DIRECTORY rviz DESTINATION share/${PROJECT_NAME})
# install(DIRECTORY params DESTINATION share/${PROJECT_NAME})

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
